class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def walk(self):
        print("walking...")


def talk(self):
    print(self.name, "is speaking.")


p = Person("Alex", 22)
if hasattr(p, "name"):  # 判断类里是否有属性，映射
    print("l.........")

# 反射，映射，自省
# getattr() # 查
# a = getattr(p, "age")
# print(a)
#
# # hasattr() # 查
# user_command = input(">>:").strip()
# if hasattr(p, user_command):
#     func = getattr(p, user_command)
#     func()
#
# # setattr() # 增，设置一个静态属性
# # static 属性
# setattr(p, "sex", "Female")
# print(p.sex)
# # 方法
# # setattr(p, "speak", talk)
# # p.speak(p)
# # 类
# setattr(Person, "speak2", talk)
# p.speak2()

# delattr() # 删
# delattr(p, "age")
# p.age
print(__name__)  # __main__就代表模块本身，
if __name__ == "__main__":  # 只会在被别的模块导入的时候发挥作用
    pass
